import store from './store'
import {
    ADDCART,
    CHANGE_SELECT,
    GETNUM,
    GETSELECT,
    GETSELECTALL,
    GETPULATE,
} from './contant'

export default {
    computed: {
        // 下单、删除按钮
        subtext: function() {
            return store.state.subtext
        },
        // 编辑、完成按钮
        text: function() {
            return store.state.text
        },
        // 购物车商品存储
        cart: function() {
            return store.state.cart
        },
        // 总价
        total: function() {
            return store.state.total
        },
        // 全选
        checkedAll: function() {
            return store.state.checkedAll
        }
    },
    methods: {
        // 添加购物车
        onAddCart(carts) {
            store.commit(ADDCART, carts)
        },
        // 编辑删除文字切换
        onText(select) {
            store.commit(CHANGE_SELECT, select)
        },
        // 数量改变计算总价
        onNum(keyword) {
            store.dispatch(GETNUM, keyword)
        },
        // 选中单个商品计算价格、全部单个选中全选高亮
        onSelect(name) {
            store.dispatch(GETSELECT, name)
        },
        // 全部商品选中计算总价
        onAllSelect(checked) {
            store.dispatch(GETSELECTALL, checked)
        },
        // 编辑、删除操作
        onPulate() {
            store.dispatch(GETPULATE)
        }
    }
}